package com.wanyu.video.nio.zero.copy;

import java.io.FileInputStream;
import java.net.InetSocketAddress;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

public class NIOZeroCopyClient {

    public static void main(String[] args) throws Exception {


        FileInputStream fileInputStream = new FileInputStream("C:\\Users\\10734\\Desktop\\学习笔记\\大数据学习笔记\\kafka学习\\kafka学习.zip");

        FileChannel channel = fileInputStream.getChannel();

        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.connect(new InetSocketAddress("127.0.0.1", 6666));
        long startTime = System.currentTimeMillis();
        channel.transferTo(0,channel.size(),socketChannel);
        System.out.println("copy耗时： " + (System.currentTimeMillis() - startTime) + " 上传文件大小： " + channel.size());
        channel.close();
    }
}
